package com.tanhua.server.controller;

import com.tanhua.domain.vo.RecommendQueryVo;
import com.tanhua.domain.vo.TodayBestVo;
import com.tanhua.server.serivce.IMService;
import com.tanhua.server.serivce.TodayBestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
@Slf4j
public class TodayBestController {

    @Autowired
    private TodayBestService todayBestService;

    /**
     * 接口名称：今日佳人
     * 接口路径：GET/tanhua/todayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity<Object> todayBest(){
        return todayBestService.queryTodayBest();
    }

    /**
     * 接口名称：推荐朋友 (首页推荐)
     * 接口路径：GET/tanhua/recommendation
     */
    @GetMapping("recommendation")
    public ResponseEntity<Object> recommendation(RecommendQueryVo vo){
        return todayBestService.queryRecommendation(vo);
    }

    /**
     * 接口名称：佳人信息
     * 接口路径：GET/tanhua/:id/personalInfo
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity<Object> queryPersonalInfo(@PathVariable("id") Long recommendUserId){
        return todayBestService.queryPersonalInfo(recommendUserId);
    }

    /**
     * 接口名称：查询陌生人问题
     * 接口路径：GET/tanhua/strangerQuestions
     */
    @GetMapping("strangerQuestions")
    public ResponseEntity<Object> strangerQuestions(Long userId){
        return todayBestService.strangerQuestions(userId);
    }

    @Autowired
    private IMService imService;

    /**
     * 接口名称：回复陌生人问题
     * 接口路径：POST/tanhua/strangerQuestions
     */
    @PostMapping("strangerQuestions")
    public ResponseEntity<Object> replyQuestion(@RequestBody Map<String,Object> paramMap){
        Long userId = Long.parseLong(paramMap.get("userId").toString());
        String reply = (String) paramMap.get("reply");
        return imService.replyQuestion(userId,reply);
    }

    /**
     * 接口名称：搜附近
     * 接口路径：GET/tanhua/search
     */
    @GetMapping("search")
    public ResponseEntity<Object> searchNear(String gender,Long distance){
        return todayBestService.searchNear(gender,distance);
    }


    /**
     * 接口名称：探花-左滑右滑
     * 接口路径：GET/tanhua/cards
     */
    @GetMapping("cards")
    public ResponseEntity<Object> queryCardsList(){
        return todayBestService.queryCardsList();
    }

    /**
     * 接口名称：探花—喜欢
     * 接口路径：GET/tanhua/:id/personalInfo
     */
    @GetMapping("{id}/love")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.todayBestService.likeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 接口名称：探花——不喜欢
     * 接口路径：GET/tanhua/:id/unlove
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> disLikeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.todayBestService.disLikeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
